function createRequestObject(){
	var xmlHttp;
	try{
		// Firefox, Opera 8.0+, Safari
		xmlHttp=new XMLHttpRequest();

	}catch (e)	{
		// Internet Explorer
		try{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}catch (e)	{
			try{
				xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
			}catch (e)	{
				alert("Your browser does not support AJAX!");
				return false;
			}
		}
	}

	return xmlHttp;

} 

var req = createRequestObject(); 

function IsNumeric(strString,type)//  check for valid numeric strings	
{
	if(type == 1)
		var strValidChars = "0123456789";
	else if(type == 2)
		var strValidChars = "0123456789.";
	else
		var strValidChars = "0123456789.-";
	var strChar;
	var blnResult = true;
	
	if (strString.length == 0) return false;
	
	//  test strString consists of valid characters listed above
	  for (i = 0; i < strString.length && blnResult == true; i++)
	  {
		  strChar = strString.charAt(i);
		  if (strValidChars.indexOf(strChar) == -1)
			blnResult = false;
	  }
	return blnResult;
}
function trim(str)
{
	return str.replace(/^\s+|\s+$/g,"");
}
function isValidEmail(el)
{        
		var str=trim(el);
		var filter=/^([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/;

		var testresults;
		if (filter.test(str))
				testresults=true;
		else 
				testresults=false;
		return (testresults);
}
function TestFileType( fileName, fileTypes )
{
	if (!fileName)
		return 1;
	
	fileName = fileName.toLowerCase();

	dots = fileName.split(".")
	//get the part AFTER the LAST period.
	fileType = "." + dots[dots.length-1];
	newfiletypes = ".jpeg,."+fileTypes.join(".");
		
	if(newfiletypes.indexOf(fileType) == -1)
	{
		//alert("Please upload only files with extension: \n\n" + (fileTypes.join(" .")) + "\n\nPlease select a new file and try again.");
		alert("Please upload only file with extension: \n(" + (fileTypes.join(" ."))+")" );
		return 0;
	}
	else
	{
		return 1;
	}
	return 0;

}
function trim_all(strObjName)
{ 
	//this function removes the spaces from the variables
        var strObj = strObjName;
        var strRet = "";
        for (i=0;i < strObj.length;i++)
        {
                if(strObj.charAt(i) != " " && strObj.charAt(i) != "")
                        strRet = strRet+strObj.charAt(i);
        }
        return strRet;
}


function TabDashboardAlbum(val)
{
        myRand=parseInt(Math.random()*99999999);
		var strUrl = WWWROOT+"/account/PostDbAlbums.php?page=dashboard&rand="+myRand+"&seltab="+val;
		req.open('get', strUrl); 
	    req.onreadystatechange = handleHPTabResponse; 
    	req.send(null);  
  
}

function handleHPTabResponse()  
{         
        
        if(req.readyState == 4)
        { 
            var response = req.responseText; 
            document.getElementById('divTabContent').innerHTML=response;	       
            document.getElementById('divloadprocess').style.display='none';
       } 
        else if(req.readyState != 4)
        {
           document.getElementById('divloadprocess').style.display='';
        }
}



function DeleteDashboardAlbum(albumid,seltab)
{
   if(confirm('Are you sure you want to delete this album?'))
   {			
        myRand=parseInt(Math.random()*99999999);
		req.open('get', WWWROOT+"/account/PostDbAlbums.php?page=dashboard&mode=deletealbum&rand="+myRand+"&albumid="+albumid+"&seltab="+seltab); 
	    req.onreadystatechange = handleHPDeleteResponse; 
    	req.send(null);  
   }
}

function handleHPDeleteResponse()  
{         
        
        if(req.readyState == 4)
        { 
            var response = req.responseText; 
            document.getElementById('divTabContent').innerHTML=response;	       
            document.getElementById('divloadprocess').style.display='none';
        } 
        else if(req.readyState != 4)
        {
           document.getElementById('divloadprocess').style.display='';
        }
}

function OrderDashboardAlbum(aid,uid,ow)
{
    myRand=parseInt(Math.random()*99999999);
	req.open('get', WWWROOT+"/account/GetEditInfo.php?rand="+myRand+"&aid="+aid+"&uid="+uid+"&ow="+ow); 
	req.onreadystatechange = handleHPOrderResponse; 
    req.send(null);  
}

function handleHPOrderResponse()  
{         
        
        if(req.readyState == 4)
        { 
			document.getElementById('divloadprocess').style.display='none';
			
            var response = req.responseText; 
			arr_res=response.split("|||");
			if(arr_res[0]==1)
			{
				 jAlert('The album is currently edited by another user, please try after some time!', 'Pixable', function(r)
				{}); 				
			}
			else
			{
				location.href=WWWROOT+"/Album/index.php?aid="+arr_res[1]+"&uid="+arr_res[2]+"&ow="+arr_res[3];
			}
        } 
        else if(req.readyState != 4)
        {
           document.getElementById('divloadprocess').style.display='';
        }
}


function checkTopLogin()

{
    var email = document.topLogin.useremail;
	var password = document.topLogin.userpass;
	//var reTESTfirstchar = /^[a-zA-Z]*$/;
	var reEmail = /^[0-9a-zA-Z_\.-]+\@[0-9a-zA-Z_\-]+\.[0-9a-zA-Z_\.-]*$/;
	   
	if(trim_all(email.value) == "" || (email.value) == 'example@example.com')
	{
		alert("Please enter email.");
		email.focus();
		return false;
	}
	if(!reEmail.test(email.value)){
		alert("E-mail address must be in the following format:'example@example.com'.");
		email.focus();
		return false;
	}	
	
	if(trim_all(password.value) == "" || (password.value) == 'pixable'){
		alert("Please enter password.");
		password.focus();
		return false;
	}
	if(password.value.length < 6){
	    alert("Password must have minimum six digits.");
		password.focus();
		return false;
	}
	
	document.topLogin.frmval.value = 1;
	myRand=parseInt(Math.random()*99999999);
	strUrl = WWWROOT+"/login/PostLogin.php?frmval=1&rand="+myRand+"&useremail="+email.value+"&userpass="+password.value;
		
	new Ajax.Request(strUrl, {
		method: 'get',
		 onSuccess: function(transport) { 
			 if(transport.responseText == 1)
				window.location = WWWROOT+"/account/index.php";
			 else
			 {
				/* Lightview.show({ href: 'divErrMsg', rel: 'inline', options: { width: 380, height: 70,topclose: true }}); */
				Lightview.show({ href: WWWROOT+'/login/message.html', rel: 'ajax', 
							   options: { width: 370, height: 45,topclose: true }});
				
				
			 }
		  }
		  

	});	
}

//Function for Phone number validation
// Declaring required variables
var digits = "0123456789";
// non-digit characters which are allowed in phone numbers
var phoneNumberDelimiters = "()- ";
// characters which are allowed in international phone numbers
// (a leading + is OK)
var validWorldPhoneChars = phoneNumberDelimiters + "+";
// Minimum no of digits in an international phone no.
var minDigitsInIPhoneNumber = 10;

function isInteger(s)
{   var i;
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < 0) || (c > 9))) return false;
    }
    // All characters are numbers.
    return true;
}
function trim(s)
{   var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not a whitespace, append to returnString.
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (c != " ") returnString += c;
    }
    return returnString;
}

function stripCharsInBag(s, bag)
{   var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function checkInternationalPhone(strPhone){
var bracket=3
strPhone=trim_all(strPhone)
if(strPhone.indexOf("+")>1) return false;
if(strPhone.indexOf("(")!=-1 && strPhone.indexOf(")")==-1)return false;
if(strPhone.indexOf("(")==-1 && strPhone.indexOf(")")!=-1)return false;
s=stripCharsInBag(strPhone,validWorldPhoneChars);
return(isInteger(s) && s.length >= minDigitsInIPhoneNumber);
}
//End of the Function.
function chklogin(id){
  document.getElementById(id).value = "";
}
/*****************************************/
function SetRadioValue(val)
{
	document.frmSettings.rdoSettings[val].checked = true;
}
function OpenSettingsWindow(albumid)
{
		Lightview.show({ href: WWWROOT+'/account/album/privacysettings.php?id='+albumid, rel: 'iframe', 
							   options: { width: 410, height: 190,topclose: true }});
		
		
}
/*
function OpenSettingsWindow(albumid)
{
		Dialog.confirm({url: WWWROOT+"/account/album/privacysettings.php?id="+albumid, options: {method: 'get'}}, {className: "alphacube", width:410, okLabel: "Save", cancelLabel: "Close", 
			 onOk:function(win)
			 { 
				myRand=parseInt(Math.random()*99999999);
                
				selection = document.frmSettings.rdoSettings;
								
				for (var i=0; i < document.frmSettings.rdoSettings.length; i++)
			    {
			   	  if (document.frmSettings.rdoSettings[i].checked)
					var settings = document.frmSettings.rdoSettings[i].value;  		
			   }
			
				strUrl = WWWROOT+"/account/album/PostAlbumInfo.php?page=detail&mode=savesettings&rand="+myRand+"&albumid="+albumid+"&settings="+settings;
				
				new Ajax.Request(strUrl, {
					method: 'get',
					 onSuccess: function(transport) { 
					 	document.getElementById('divsettingContent').style.display='none';
						//document.getElementById('divsettingContent').innerHTML = '';
						document.getElementById('btnOk').style.display='none';
					 	//document.frmSettings.rdoSettings[transport.responseText].checked = true;
					  }
				});	
				
				$('divsettings_error_msg').innerHTML='<BR>Your settings has been saved successfully.<BR><BR>';
				$('divsettings_error_msg').show(); 
				Windows.focusedWindow.updateHeight();
				//new Effect.Shake(Windows.focusedWindow.getId());
				
				return false;
			}
	});
}
*/

function CopyMyAlbum(albumid,page,contentdiv,status)
{
	myRand=parseInt(Math.random()*99999999);
	document.getElementById('divloadcontent').style.display='';
	strUrl = WWWROOT+"/account/copyalbum.php?rand="+myRand+"&albumid="+albumid;
	new Ajax.Request(strUrl, {
		method: 'get',
		evalJS : true,
		onSuccess: function(transport) {
				var msg = transport.responseText;
				GetMyBooks(page,contentdiv,status,msg);
			}
	});	
}
/***************Delete album**************/
function DeleteAlbum(albumid,page,contentdiv,status)
{
   
   if(document.getElementById('hdnStatus'))
   		status = document.getElementById('hdnStatus').value;  // This is used to show all/published/in progress books tab
   else
   		status = '';
		
   myRand=parseInt(Math.random()*99999999);
   if(confirm('Are you sure you want to delete this album?'))
   {		
   		document.getElementById('divloadcontent').style.display='';   
   		strUrl = WWWROOT+"/account/album/PostContent.php?page="+page+"&mode=deletealbum&rand="+myRand+"&albumid="+albumid+"&status="+status;
		new Ajax.Request(strUrl, {method: 'get',onSuccess: function(transport){ 
				var msg = transport.responseText;
				GetMyBooks(page,contentdiv,status,msg);
			}
		});	
  }	
}

function GetMyBooks(page,contentdiv,status,msg)
{
	var myRand=parseInt(Math.random()*99999999);
	var strUrl = WWWROOT+"/account/album/PostContent.php?page="+page+"&rand="+myRand+"&status="+status;
	new Ajax.Request(strUrl, {
		method: 'get',
		onSuccess: function(transport){
			if(msg){
				alert(msg);
			}
			document.getElementById(contentdiv).innerHTML=transport.responseText;
			document.getElementById('divloadcontent').style.display='none';
			}
		});	
}

function CommaSeparatedEmail(str){
   var check=0;
   var myArray = str.split(','); 
     for(var i=0;i<myArray.length;i++){
	   var str_email=myArray[i];
	   if(str_email!=""){
	   if(!reEmail.test(str_email.value)){
		check=1;
	   }
	   }
	 }
	 return check;
}
function DeleteFacebookAlbum(albumid,page,contentdiv)
{
   
   if(document.getElementById('hdnStatus'))
   		status = document.getElementById('hdnStatus').value;  // This is used to show all/published/in progress books tab
   else
   		status = '';
		
   myRand=parseInt(Math.random()*99999999);
   if(confirm('Are you sure you want to delete this album?'))
   {		
        document.getElementById('divloadcontent').style.display='';
   		strUrl = WWWROOT+"/connect/PostContent.php?page="+page+"&mode=deletealbum&rand="+myRand+"&albumid="+albumid+"&status="+status;
		new Ajax.Request(strUrl, {method: 'get',onSuccess: function(transport) 
		{ 
			document.getElementById(contentdiv).innerHTML=transport.responseText;		
			document.getElementById('divloadcontent').style.display='none';
	  }
	});	
  }
	
}

function ShowHideDiv(divname)
{
	if(document.getElementById(divname).style.display == '')
	{
		document.getElementById(divname).style.display = 'none';
		document.getElementById('divClose').innerHTML = 'Choose Options';
		document.getElementById('divviewabletext').innerHTML = 'Options have been set';
	}
	else
	{
		document.getElementById(divname).style.display = '';
		document.getElementById('divClose').innerHTML = 'Close';
		document.getElementById('divviewabletext').innerHTML = '';
	}
}
/* document.observe('lightview:hidden', function()
{
	if(document.getElementById('useremail'))
	 document.getElementById('useremail').focus();
}); */


function refreshpage()
{ 
 var loc = location.href;
 location.href=loc;
}

function OpenAdd(id)
{
	if(id==0)
	{
		writeCookie("PageAccess","CreateAlbum");
		location.href=WWWROOT+"/account/album/addalbum.php";
	}
	else
	{	
		location.href=WWWROOT+"/account/album/addalbum.php?fbaid="+id;
	}
}

function OpenGallery()
{ 
	WWWROOT=WWWROOT.replace("https","http");
	writeCookie("PageAccess","AlbumGallery");
 	location.href= WWWROOT+'/gallery/index.php';	
}


function OpenPricing()
{ 
	WWWROOT=WWWROOT.replace("https","http");
	writeCookie("PageAccess","PricingShipping");
 	location.href= WWWROOT+'/pricing/index.php';				
}

function OpenMyAlbum()
{ 
	WWWROOT=WWWROOT.replace("https","http");
	writeCookie("PageAccess","MyAlbums");
 	location.href= WWWROOT+'/account/index.php';  
}  
  
  
function openAlert(id)
{
	WWWROOT_SEC = WWWROOTS;
    location.href=WWWROOTS+"/account/album/albumshipping.php?id="+id;
}

function writeCookie(name, value)
{
	 var expire = "";
	 expire = new Date((new Date()).getTime() + 60 * 60 * 24 * 365);
     expire = "; expires=" + expire.toGMTString();
     document.cookie = name + "=" + escape(value) + expire;
}

/* Calendar Tabs */
function OpenMyCalendar()
{ 
	WWWROOT=WWWROOT.replace("https","http");
	writeCookie("PageAccess","Calendar");
	writeCookie("RedirectTo",WWWROOT+'/calendar/my_calendars.php');
 	location.href= WWWROOT+'/calendar/my_calendars.php';	
}

function OpenCalendarPricing()
{ 
	WWWROOT=WWWROOT.replace("https","http");
	writeCookie("PageAccess","Calendar");
	writeCookie("RedirectTo",WWWROOT+'/pricing/calendar.php');
 	location.href= WWWROOT+'/pricing/calendar.php';	
}

function OpenCreateCalendar()
{ 
	WWWROOT=WWWROOT.replace("https","http");
	writeCookie("PageAccess","Calendar");
	writeCookie("RedirectTo",WWWROOT+'/calendar/step1.php');
 	location.href= WWWROOT+'/calendar/step1.php';	
}
/* Calendar Tabs ends */

//---------Start----.---Vinod----------------------------------------------
	function ltrim(stringToTrim) {
				return stringToTrim.replace(/^\s+/,"");
			}

	function rtrim(stringToTrim) {
				return stringToTrim.replace(/\s+$/,"");
			}	

	function isspecial_characters(Profile_Value,Profile_length)
	{
	  //	var iChars = "!@#$%^&*()+=-[]\';,./{}|\":<>?";
            var iChars = "!@#$%^*+=[]\';{}|\"<>";
		for (var i = 0; i < Profile_length; i++) {
			if (iChars.indexOf(Profile_Value.charAt(i)) != -1)
			{
			  //alert("Please remove special characters or the symbols.\n");
				return false;
			}
		}
	 }
	 function white_space(field)
	{
		field1 = document.getElementById(field);
		document.getElementById(field).value = field1.value.replace(/^\s*|\s*$/g,'');
		return "";
	}
spacenotallowed = function(ide){
		Profile_LVal = ltrim(eval("document.getElementById(ide).value"));
		Profile_RVal = rtrim(eval("document.getElementById(ide).value"));
		Profile_Focus = eval("document.getElementById(ide)");

		Profile_Value = eval("document.getElementById(ide).value");
		Profile_length = Profile_Value.length;

        if(Profile_Value.length != Profile_LVal.length){
			//alert("Please remove the spaces.");
			//Profile_Focus.value = '';
			white_space(ide);
			Profile_Focus.focus();
      		return false; //(Field+" cannot contain spaces, special characters or the symbols.\n");
		}
        else if(Profile_Value.length != Profile_RVal.length){
			//alert("Please remove the spaces.");
			//Profile_Focus.value = '';
			white_space(ide);
			Profile_Focus.focus();
			return false;
      		//return (Field+" cannot contain spaces, special characters or the symbols.\n");
		}
        else if(isspecial_characters(Profile_Value,Profile_length) == false && ide != 'id_register_password'){
			//alert("Please remove special characters or the symbols.\n");
			Profile_Focus.value = '';
			white_space(ide);
			Profile_Focus.focus();
			return false;
           // return ("Please remove special characters or the symbols.\n");
		}
	}
	//--------------------------------------------------------