//function to check email
var obj
obj = "document.form2.";
PositionX = 100;
PositionY = 100;
defaultWidth  = 500;
defaultHeight = 500;
var AutoClose = true;
if (parseInt(navigator.appVersion.charAt(0))>=4){
	var isNN=(navigator.appName=="Netscape")?1:0;
	var isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;}
	var optNN='scrollbars=no,width='+defaultWidth+',height='+defaultHeight+',left='+PositionX+',top='+PositionY;
	var optIE='scrollbars=no,width=150,height=100,left='+PositionX+',top='+PositionY;
function popup(p,w,h){
	var left = (screen.availWidth/2) - (w/2);
	var top = (screen.availHeight/2) - (h/2);
	window.open(p,'Open','width='+w+',height='+h+',scrollbars=no,status=0, left='+left+', top='+top)
}

function ChangeVip(control)
{
	var Vip=document.getElementById("hiddenVIP");
	if(control.checked){
		Vip.value=1;
	}else{
		Vip.value=0;
	}
}
function checkEmail(str){
	var textValue = str.value;
	var err=''
	if (textValue == ''){
		err += "Dia chi email khong hop le";
		alert(err);
		str.focus();
		return false
	}
	if (textValue.indexOf('@') <= 0 || textValue.indexOf('@') == textValue.length -1){
		err += "Dia chi email khong hop le";		
	} else {
		var substr = textValue.substring(textValue.indexOf('@'),textValue.length);
		if (textValue.indexOf('.') <= 0) {
			err += "Dia chi email khong hop le\n";
		}
	}
	if (err != '') { 
		alert(err); 
		str.focus();
		return false;
	}
	return true;
}
function chkEmail(strEmail)
{

	strIndex= eval(obj+strEmail+".value").indexOf("@");
	strVal=eval(obj+strEmail+".value")
	len=(eval(obj+strEmail+".value").length);
	strFind = strVal.substring(strIndex,len);
	if(eval(obj+strEmail+".value").indexOf("@")< 1 || eval(obj+strEmail+".value").indexOf(".")< 1 || eval(obj+strEmail+".value").length < 5)
	{
		return false;
	}
	if  (strFind.indexOf(".")< 3) 
		return false;
	else
		return true;
}	
function validate(arrFields)
{
	var FieldsArr = arrFields.split(",");
	var arrLen = FieldsArr.length;
	returnStr = "";
	
	for (i=0;i<arrLen;i++)
	{
		indFields = FieldsArr[i].split(":");
		//indFields = trim(FieldsArr[i]);
		if(trim(eval(obj+indFields[0]+".value"))=="")
		{

			returnStr = FieldsArr[i];
			break;
		}
	}
	return returnStr;
}


function trim(strText) { 
    // this will get rid of leading spaces 
    while (strText.substring(0,1) == ' ') 
        strText = strText.substring(1, strText.length);

    // this will get rid of trailing spaces 
    while (strText.substring(strText.length-1,strText.length) == ' ')
        strText = strText.substring(0, strText.length-1);

   return strText;
} 
function MM_openBrWindow(theURL,winName,features) { //v2.0
 	var newWind=window.open(theURL,winName,features);
	//if(newWind.opener==null){
		//newWind.opener=self
	//}
}
function ViewMe(filename){
	var url=filename//"preview_picture.php?picture_id="+ document.hotel.NewImageID.value
	var winname="ViewPhoto"
	var features="width=500,height=300,top=50,left=50,scrollbars=yes"
	MM_openBrWindow(url,winname,features);
}
function ViewAlbum(filename){
	var url=filename//"preview_picture.php?picture_id="+ document.hotel.NewImageID.value
	var winname="ViewAlbum"
	var features="width=500,height=500,top=50,left=50,scrollbars=yes"
	MM_openBrWindow(url,winname,features);
}
function ViewProfile(filename){
	var url=filename//"preview_picture.php?picture_id="+ document.hotel.NewImageID.value
	var winname="ViewPhoto"
	var features="width=800,height=600,top=50,left=50,scrollbars=yes"
	MM_openBrWindow(url,winname,features);
}

function ShowPhoto(marao){
	if(isIE){
		var features="dialogWidth=800,dialogHeight=600,dialogTop=50,dialogLeft=50,scroll=no,status=no,location=no"
		window.showModelessDialog('ajaxuploader/index.php?MaRao='+marao,features,'');
	}else{
		var w=window.open('ajaxuploader/index.php?MaRao='+marao, "newWin", "modal=1, width=500, height=400");
		w.focus();

	}
}
function AdvShowPhoto(marao){
	if(isIE){
		var features="dialogWidth=800,dialogHeight=600,dialogTop=50,dialogLeft=50,scroll=no,status=no,location=no"
		window.showModelessDialog('../ajaxuploader/index.php?MaRao='+marao,features,'');
	}else{
		var w=window.open('../ajaxuploader/index.php?MaRao='+marao, "newWin", "modal=1, width=500, height=400");
		w.focus();

	}
}
function addf(customer){
	var url="addfavor.php?CustomerID=" + customer;
	 ViewMe(url);
}
function ViewDetail(marao){
	var url="xemchitiet.php?MaRao=" + marao;
	 ViewProfile(url);
}
function deletef(customer){
	var url="deletefavor.php?CustomerID=" + customer;
	 ViewMe(url);
}
function addfavor(customer){
	var url="scripts/addfavor.php?CustomerID=" + customer;
	 ViewMe(url);
}

function newWin(url,width,height) {
    window.open(url,"remoteWin","width="+width+",height="+height+",resizable=0,menubar=0,status=0,scrollbars=1");
}



function popImage(imageURL,imageTitle){
if (isNN){imgWin=window.open('about:blank','',optNN);}
if (isIE){imgWin=window.open('about:blank','',optIE);}
with (imgWin.document){
writeln('<html><head><title>Loading...</title><style>body{margin:0px;}</style>');writeln('<sc'+'ript>');
writeln('var isNN,isIE;');writeln('if (parseInt(navigator.appVersion.charAt(0))>=4){');
writeln('isNN=(navigator.appName=="Netscape")?1:0;');writeln('isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;}');
writeln('function reSizeToImage(){');writeln('if (isIE){');writeln('window.resizeTo(300,300);');
writeln('width=300-(document.body.clientWidth-document.images[0].width);');
writeln('height=300-(document.body.clientHeight-document.images[0].height);');
writeln('window.resizeTo(width,height);}');writeln('if (isNN){');       
writeln('window.innerWidth=document.images["George"].width;');writeln('window.innerHeight=document.images["George"].height;}}');
writeln('function doTitle(){document.title="'+imageTitle+'";}');writeln('</sc'+'ript>');
if (!AutoClose) writeln('</head><body bgcolor=000000 scroll="no" onload="reSizeToImage();doTitle();self.focus()">')
else writeln('</head><body bgcolor=000000 scroll="no" onload="reSizeToImage();doTitle();self.focus()" onblur="self.close()">');
writeln('<a title="Close" href="javascript:window.close();">');
writeln('<img border=0 name="George" src='+imageURL+' style="display:block"></a></body></html>');
close();		
}}
var message="";
///////////////////////////////////
function isEmpty(s)
{   return ((s == null) || (s.length == 0))
}
function isDigit (c)
{   return ((c >= "0") && (c <= "9"))
}
function isInteger (s)

{   var i;

    if (isEmpty(s)) 
       if (isInteger.arguments.length == 1) return true;
       else return (isInteger.arguments[1] == true);

    // Search through string's characters one by one
    // until we find a non-numeric character.
    // When we do, return false; if we don't, return true.

    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);

        if (!isDigit(c)) return false;
    }

    // All characters are numbers.
    return true;
}
function signup(){
	document.location="scripts/step.php";
}

function initailize_pics () {
		
		if(document.images['image_0']!=null){
			document.images['image_0'].src = image_1.src ;
		}
		for ( x=1; x <=4; x++) {
			if(document.images["image_'+ x + '"]!=null){
				eval('document.images["image_'+x+'" ].src = image_'+x+'_th.src;');
			}
		}
		
	}
		function swap_photo(loc_to , loc_from){
		
		img_1 = eval(loc_to + '.src')  ;
		//alert(img_1);
		//img_1_th = eval(loc_to + '_th.src')  ;
		
		//img_2 = eval( loc_from + '.src')  ;
		img_2_th = eval( loc_from + '_th.src')  ;
		document.images[loc_to].src = img_2_th ;
		window.focus();
		
		}