function reloadPage(init) {  //reloads the window if Nav4 resized
    if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
        document.pgW=innerWidth; document.pgH=innerHeight; onresize=reloadPage; }}
    else if (innerWidth!=document.pgW || innerHeight!=document.pgH) location.reload();
}
reloadPage(true);

function preloadImages() { //v3.0
    var d=document; if(d.images){ if(!d.p) d.p=new Array();
    var i,j=d.p.length,a=preloadImages.arguments; for(i=0; i<a.length; i++)
        if (a[i].indexOf("#")!=0){ d.p[j]=new Image; d.p[j++].src=a[i];}}
}

function swapImgRestore() { //v3.0
    var i,x,a=document.sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function findObj(n, d) { //v4.01
    var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
        d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
    if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
    for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=findObj(n,d.layers[i].document);
    if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function swapImage() { //v3.0
    var i,j=0,x,a=swapImage.arguments; document.sr=new Array; for(i=0;i<(a.length-2);i+=3)
        if ((x=findObj(a[i]))!=null){document.sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}


// Validate Required


function validateRequired(field, msg, min, max){
	var test = "pass";

	if(field.value.length == 0) {
		test = "fail";
	}else if(min && field.value.length < min) {
		msg = msg + "\nMin Lenght should be " + min;
		test = "fail";
	}else if(max && field.value.length > max) {
		msg = msg + "\nMax Lenght should be " + max;
		test = "fail";
	}
	
	if(test == "fail"){
		alert(msg)
		field.focus();
		field.select();
		return false;
	}
	
	return true;
}

// Validate Number
function validateNumber(field, msg, min, max){
	if (!min) { min = 0 }
	if (!max) { max = 255 }

	if ( (parseInt(field.value) != field.value) ||
             field.value.length < min ||
             field.value.length > max) {
		alert(msg);
		field.focus();
		field.select();
		return false;
	}

	return true;
}

// Validate Mail IDs
function validateEmail(field, msg){
	if (!field.value) {
		return true;
	}

	var re_mail = /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z])+$/;
	if (!re_mail.test(field.value)) {
		if (msg != '') { alert(msg) }
		field.focus();
		field.select();
		return false;
	}
    
	return true;
}
 

// Validate Alpha-Numeric
function validateAlphaNumeric(field, msg){
	var numaric = field.value;
	for(var j=0; j<numaric.length; j++) {
		var alphaa = numaric.charAt(j);
		var hh = alphaa.charCodeAt(0);
		
		if(!(hh > 47 && hh<59) || (hh > 64 && hh<91) || (hh > 96 && hh<123)){
			if (msg != ''){
				alert(msg);
			}
			field.focus();
			field.select();
			return false;
		}
	}
	return true;
}

// Validate Alpha-Numeric
function validateCombo(field, msg){
	
	if(field.selectedIndex == 0){
		if (msg != ''){
			alert(msg);
		}
		field.focus();
		return false;
	}

	return true;
}

// Validate Extension
function CheckExtension(field, msg){
	
	var ext = field.value.split(".")
	if(ext[1] != 'jpg'){
		if (msg != ''){
			alert(msg);
		}
		field.focus();
		return false;
	}

	return true;
}
// Validate image h x w
function Checkhxw(field){
	 alert(field.value);
	   var newImg = new Image();
        newImg.src = field.value;
      var height = newImg.height;
      var width = newImg.width;
      alert(height);
   
}
function compareFields(field1, field2, msg) {

	if(field1.value != field2.value) {
		if (msg != ''){
			alert(msg)
		}
		return false;
	}
    
	return true;
}

// to check value as true
function checkValue(field, msg, val) {
	
	if (!val) val = 'true';
	if(field.value != val) {
		if (msg != ''){
			alert(msg);	
		}
		return false;
	}
	return true;
}


//created by ragav for using epaper shown on mouseover
function showephoto(val) {
		document.getElementById('im'+val).style.display = 'block';
		for(i=1; i<=4; i++){
			if(i!=val)	
			document.getElementById('im'+i).style.display = 'none';
		}
	}
function hideephoto(){
	for(i=1; i<=4; i++){
		document.getElementById('im'+i).style.display = 'none';
	}
}
	
function showTab(vID, vTabCount, vSelIntex, vVal) {
	lStyle = 'tab'; 
	for(i = 0; i < vTabCount; i++) {
		tt	=	document.getElementById('tt'+i+"_"+vID);
		dd	=	document.getElementById('dd'+i+"_"+vID);
		if(i==vSelIntex) {
			tt.className	=	lStyle+'HeadActive';
			dd.className	=	lStyle+'BodyActive';
		} else {
			tt.className	=	lStyle+'HeadInActive';
			dd.className	=	lStyle+'BodyInActive';
			if(vVal){
				dd.innerHTML='';
			}			
		}
	}
	AjaxChange('dd'+vSelIntex+"_"+vID, vVal);
}

function Inint_AJAX() {
try { return new ActiveXObject("Msxml2.XMLHTTP");  } catch(e) {} //IE
try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch(e) {} //IE
try { return new XMLHttpRequest();          } catch(e) {} //Native Javascript
alert("XMLHttpRequest not supported");
return null;
};

function AjaxChange(id, val) {
var req = Inint_AJAX();
req.onreadystatechange = function () {
 if (req.readyState==4) {
      if (req.status==200) {
           document.getElementById(id).innerHTML=req.responseText; //retuen value
      }
 }
};
req.open("GET", "issue.php?val="+val); //make connection
req.send(null); //send value
}
