/*
*	This Js files contians Function to create the XMLHTTP request to communicate with the server through AJAX
*	Code 		: Alok Kumar
*	Modified 	: Umesh Kumar Sharma
*	COMPANY		: Chetu India Pvt Ltd.
*/

//Function used to create the AJAX Object to communicate with server.	-	starts here
function makeInstance() 
	{	
		var http_request = false;	
		if (window.XMLHttpRequest) 
			{ // Mozilla, Safari,...  
				try{
					http_request = new XMLHttpRequest();	
				}
				catch(e){

				}
			} 
		else if (window.ActiveXObject) 
			{ // IE  
					try 
						{  
							http_request = new ActiveXObject("Msxml2.XMLHTTP");  
						} 
					catch (e) 
						{  
							try 
								{  	
									http_request = new ActiveXObject("Microsoft.XMLHTTP");  
								} 
							catch (e) {}  
						}	
				}	
			if (!http_request) 
				{ 
					return false;	
				}	
			return http_request;
	}
	//ends here AJAX Object
	
	//Function to check the valid user name
	function valide1(uname){
		document.getElementById("uname").value = document.getElementById("uname").value.toLowerCase();
		var text = document.getElementById("uname").value;
		
		
	   // alert(uname);
		validator.open('POST', 'checkusername.php', true);	
		validator.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');	
		validator.send('uname=' + text);
		validator.onreadystatechange = showResponseUser;
	}

	//Function to check the valid user name
	function validea(uname) 
	{	
		var text = document.getElementById("email").value;
	   // alert(uname);
		validator.open('POST', 'checkusername.php', true);	
		validator.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');	
		validator.send('email=' + text);
		validator.onreadystatechange = showResponse;
	}
		
	//Function to check the valid user name validate 2
	function valide2(uname) 
	{	
		var text = document.getElementById("cname").value;
	   // alert(uname);
		validator.open('POST', 'checkusername.php', true);	
		validator.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');	
		validator.send('cname=' + text);
		validator.onreadystatechange = showResponse1;
	}


function click5(cnt)
{
    validator.open('POST', 'createtebox1.php', true);	
	validator.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');	
	validator.send('nobs=' + cnt);
	validator.onreadystatechange = showResponse3;


}
	//Function to check wheater the value is number of not
	function is_number(number)
	{
		if(!number.match(/^[\-\+0-9e1-9]+$/))
			return false;
		return true;
	}
	//Function to check that is string empty 		
	function is_empty(str)
	{
  		 str=trim(str);
		 if ((str.length==0)||(str==null))
			return true;
		 return false;
	}

	//Function to remove the space from both side
	function trim(inputString) 
	{
	   inputString=inputString.replace(/^\s+/g,"");
	   inputString=inputString.replace(/\s+$/g,"");
	   return inputString;
	} // Ends the "trim" function

		
	/**
	*	 Validate Seema-Code and QR-Code, input number to generate Bulk-Tag
	*/
	function valide3(nob) 
	{	
		var text = document.getElementById("nobs").value;
        var text1 = document.getElementById("nobq").value;
	 
	 	
	
	 /* if(!is_empty(text) && !is_number(text))
		{
        alert("Please enter valid number between 1 To 10 for Seema Code");
		document.getElementById("nobs").focus();
		return false;
		}
	
	  if(!is_empty(text1) &&!is_number(text1))
		{
			alert("Please enter valid number between 1 To 10 for QR Code");
			document.getElementById("nobq").focus();
			return false;
		}
				
	  
		
	  if(!is_empty(text) && ( (text>10) || (text< 1)))
		{
			alert("Please enter valid number between 1 To 10 for Sema Code");
			document.getElementById("nobs").focus();
			return false;
		}
     
	  if(!is_empty(text1) && ((text1>10) || (text1< 1)  ))
		{
			alert("Please enter valid number between 1 To 10 for QR Code");
			document.getElementById("nobq").focus();
			return false;
		}
		*/
	  if(is_empty(text) && is_empty(text1)){
		   alert("Please choose number of tag to make either Datamatrix or QR Code.");
		  document.getElementById("nobs").focus();
		  return false;
	  }
	   document.getElementById('frmaction').value=1
	   
	   document.frm.submit(); 

	}
  
  //Function valide4
  function valide4(nob) 
	{	
		var text = document.getElementById("nobq").value;
	   // alert(uname);
		if(document.getElementById("nobq").value > nob)
		{

	    alert("Maximum limit for tag creation is :100");
		return false;
		}
		
		
		validator.open('POST', 'createtebox1.php', true);	
		validator.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');	
		validator.send('nobq=' + text);
		validator.onreadystatechange = showResponse4;
	}






//	Function to validate the User Name and Password
function validate(uname) 
	{	
		var text1 = document.getElementById("uname").value;
	 	var text2 = document.getElementById("password").value;
	    //alert(text1);
		//alert(text2);
		validator.open('POST', 'checkusername.php', true);	
		validator.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');	
		validator.send('name=' + text1 +'&password=' + text2);
		//validator.send('password=' + text2);
		validator.onreadystatechange = showResponse1;
	
	}
	

// Create the Handler

// Username handler
function showResponseUser()
	{	
		if ( validator.readyState == 4 )	
			{ 
				if(!is_empty(validator.responseText)){
					document.getElementById('uservalid').value = 1;
					document.getElementById('message').innerHTML = validator.responseText;
				}
				else{
					document.getElementById('uservalid').value = 0;
					document.getElementById('message').innerHTML = "";	
					document.getElementById('uname').value = document.getElementById('uname').value.toLowerCase();
				}
			}
	}

	
// Email handler
function showResponse()
	{	
		if ( validator.readyState == 4 )	
			{ 
				if(!is_empty(validator.responseText)){
					document.getElementById('emailvalid').value = 1;
					document.getElementById('message').innerHTML = validator.responseText;
				}
				else{
					document.getElementById('emailvalid').value = 0;
					document.getElementById('message').innerHTML = "";
				}
			}
	}

function showResponse1()
	{	
		if ( validator.readyState == 4 )	
			{ 
				document.getElementById('message').innerHTML = validator.responseText;
			
			}
	}// Create the Handler


function showResponse3()
	{	
		if ( validator.readyState == 4 )	
			{ 
				document.getElementById('message').innerHTML = validator.responseText;
			
			}
	}// Create the Handler

function showResponse4()
	{	
		if ( validator.readyState == 4 )	
			{ 
				document.getElementById('message1').innerHTML = validator.responseText;
			}
	}// 
	
	validator = makeInstance();
	


 

/**
*	Trasfer Page: Username Validation
*	@purpose:	called from "transfer.php", to validate username 
*				when tranfering tag to Augme's user
* 	@parameter: fld - username field
*/

var http1;
function verifyUserName(fld,tagid){
	http1 = makeInstance();
	url = "validateusername.php";
	http1.open("POST",url+"?username="+fld.value+"&tagid="+tagid,false);
	http1.onreadystatechange = handleUserNameValidation; 
	http1.send(null);
}

/**
*	Function called to handle UserName Validation
*/
function handleUserNameValidation(){
	if(http1.readyState == 4){ 
	  if(http1.status == 200){		
	   	msg = http1.responseText.split("~");
		
		user_valid = eval(document.getElementById("user_valid"+msg[1]));
		
		 if(!is_empty(msg[0])){		  	
			
			user_valid.value = '1';				
			alert(msg[0]);
		  }
		  else{
			  user_valid.value = "";			
		  }
		  
	  }	 
	}
}



	/**
	*	Profile Page: Profile Name Validation
	*	@purpose:	check duplicate profile name when adding new profile
	* 	@parameter: fld - usrprfname field
	*/
	
	var http2;
	function checkProfile(fld){
		document.getElementById('msg_id').innerHTML = "";
		http2 = makeInstance();
		url = "validateprofilename.php";
		http2.open("POST",url+"?profilename="+fld.value,true);
		http2.onreadystatechange = handleProfileValidation; 
		http2.send(null);
	}
	
	/**
	*	Function called to handle Profile Name Validation
	*/
	function handleProfileValidation(){
		if(http2.readyState == 4){
		  if(http2.status == 200){		
			 if(!is_empty(http2.responseText)){		  
				alert(http2.responseText);
				document.getElementById('usrprfname').value= "";
				//alert(document.forms.profile);
				document.getElementById('usrprfname').focus();
				document.getElementById('profileNameValidate').value= 1;
			  }
			  else{
				  document.getElementById('usrprfname').value = document.getElementById('usrprfname').value.toLowerCase();			   
				  
				  document.getElementById('profileNameValidate').value= "";		  
			  }
		  }	 
		}
	}
		

/**
*	Manage Page: Update Tag
* 	@parameter: url with tag autoincrement id 
*/

var http3;
function updateTage(t_id){
	
		/*
		*	Code to validate the tag url (validate if user put m.augme.com/123xyz or http://m.augme.com/123xyz)
		*	Created by Umesh Kumar Sharma
		*	@15 Dec 07
		*/
		var id		 = 'tagurl'+t_id;	//creating id
		var urlvalue = document.getElementById(id).value;	//set the value into variable
		
		//	Match the url 
		var flag	 = urlvalue.search(/(x)\.(augme)\.(com)/i);
		var flag1 	 = urlvalue.search(/(aug)\.(me)/i);
		if(flag!=-1 || flag1!=-1){ // if url match go into this condition 
			alert('Sorry! You can not insert x.augme.com or aug.me as url');
			document.getElementById(id).focus();
			return false
		}
		/*
		*	Ends Here
		*/
	
		http3 = makeInstance();
		url = "updatetag.php";	
		title = eval(document.getElementById('title'+t_id)).value;
		tagurl= eval(document.getElementById('tagurl'+t_id)).value;
		keys= eval(document.getElementById('key'+t_id)).value;
		
		url = url+"?t_id="+t_id+"&title="+title+"&tagurl="+tagurl+"&keyword="+keys;
		
		http3.open("POST",url,true);
		http3.onreadystatechange = handleUpdateTage; 
		http3.send(null);
}

/**
*	Function called to handle Tag Update 
*/
function handleUpdateTage(){
	if(http3.readyState == 4){
	  if(http3.status == 200){	
		document.getElementById('msg_td').className = "update_message";
	  	document.getElementById('msg_td').innerHTML ="Keywords, Title and Tag URL have been updated!!!";
		
	  }	 
	}
}

/**
*	Mobile Manage Page: Update Tag
* 	@parameter: url with tag id 
*/

var http6;
function updateTagmob(page,tagid){
	
	http6 = makeInstance();
	url = page;	
	tagurl= eval(document.getElementById('tagurl'+tagid)).value;
	
	url = url+"?tagid="+tagid+"&tagurl="+tagurl;
	
	http6.open("POST",url,true);
	http6.onreadystatechange = handleUpdateTagmob; 
	http6.send(null);
	
}

/**
*	Function called to handle Tag Update 
*/
function handleUpdateTagmob(){
	if(http6.readyState == 4){
	  if(http6.status == 200){	
		document.getElementById('msg_td').className = "update_message";
	  	document.getElementById('msg_td').innerHTML ="Tag URL has been updated!!!";
		
	  }	 
	}
}

/**
*	Make Page: Create Semacode
* 	@parameter: url 
*/

var http5;
function createSemacode(tinyurl){
	http5 = makeInstance();
	url = "createSemacode.php";	
		
	url = url+"?image="+tinyurl;
	
	http5.open("POST",url,true);
	http5.onreadystatechange = handlecreateSemacode; 
	http5.send(null);
}

/**
*	Function called to handle Create Semacode
*/
function handlecreateSemacode(){
	if(http5.readyState == 4){
	  if(http5.status == 200){	
	  	  //alert(http4.responseText);
	  }	 
	}
}

/**
*	Make Page: Create QR-Code
* 	@parameter: url 
*/

var http4;
function createQrCode(tinyurl){
	http4 = makeInstance();
	url = "createQrCode.php";	
		
	url = url+"?image="+tinyurl;
	
	http4.open("POST",url,true);
	http4.onreadystatechange = handlecreateQrCode; 
	http4.send(null);
}

/**
*	Function called to handle Create QR Code
*/
function handlecreateQrCode(){
	if(http4.readyState == 4){
	  if(http4.status == 200){	
	  	  //alert(http4.responseText);
	  }	 
	}
}


/**
*	Delete Previous Selected Tags of the current page
*   ---Remember Transfer Tags---
*/

var http7;
function preSelTagsDel(cur_page_num){
	http7 = makeInstance();
	url = "remember_tags.php";
		
	url = url+"?delPreSelTagonPage="+cur_page_num;
	
	http7.open("POST",url,false);
	http7.onreadystatechange = function handlesdelPreSelTags(){}; 
	http7.send(null);
}


/**
*	Save Selected Tags into temporary table  
*/

var http8;
function saveSelectedTags(tagData,cur_page_num,rem){
	try{
		http8 = makeInstance();
		url = "remember_tags.php";	
			
		url = url+"?tagData="+tagData+"&cur_page_num="+cur_page_num+"&rem="+rem;
		//alert(url);
		http8.open("POST",url,true);
		
		http8.onreadystatechange = handlesaveSelectedTags; 
		http8.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
		http8.send(null);
		
	}
	catch(e){

	}
}

/**
*	Function called to handle Save Selected Tags
*/

function handlesaveSelectedTags(){
	try{
		if(http8.readyState == 4){	 
		  if(http8.status != 0){
			  if(http8.status == 200) {	  	
				  if((http8.responseText == 'trans') || (http8.responseText == 'bulk'))
					  window.location.href="transfer_confirm.php?type="+http8.responseText;
						  
			  }	 
		  }
		}
	}
	catch(e){
		//alert(http8.responseText);
		//alert(http8.status);
	}
} 

/**
*	Check whether in this logged-in session, 
*	Tags is/are being selected or not 
*/

var http9;
function checkSelectedTags(){	 
	http9 = makeInstance();
	url = "remember_tags.php";		
	url = url+"?checkSelTag=yes";
	http9.open("POST",url,false);
	http9.onreadystatechange = handlecheckSelectedTags;
	http9.send(null);
}

/**
*	Function called to handle Check Selected Tags
*/
function handlecheckSelectedTags(){
	if(http9.readyState == 4){
	  if(http9.status == 200){	
		document.getElementById('checkSelTags').value=http9.responseText;			  
	  }	 
	}
}


/**
*	Save Selected Tags into temporary table  
*/

var http10;
function updadeSelectedTags(type,tranOpt,bulkprofileArr,userEmailId,usrprofileid,friendid){
	http10 = makeInstance();
	url = "remember_tags.php";	
		
	url = url+"?type="+type+"&tranOpt="+tranOpt+"&bulkprofileArr="+bulkprofileArr+"&userEmailId="+userEmailId+"&usrprofileid="+usrprofileid+"&friendid="+friendid;	
	http10.open("POST",url,false);
	http10.onreadystatechange = function handleupdadeSelectedTags(){}; 
	http10.send(null);
}



  var myWidth = 0, myHeight = 0;
  if( typeof( window.innerWidth ) == 'number' ) {
	//Non-IE
	myWidth = window.innerWidth;
	myHeight = window.innerHeight;
  } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
	//IE 6+ in 'standards compliant mode'
	myWidth = document.documentElement.clientWidth;
	myHeight = document.documentElement.clientHeight;
  } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
	//IE 4 compatible
	myWidth = document.body.clientWidth;
	myHeight = document.body.clientHeight;
  }
  
  writeWinSizeToSession(myWidth,myHeight);


/**
*	Write Window Width and Height into session variable
*/

var http11;
function writeWinSizeToSession(myWidth,myHeight){
	http11 = makeInstance();
	url = "wirteWindowSize.php";			
	url = url+"?myWidth="+myWidth+"&myHeight="+myHeight;
	//alert(url);
	http11.open("POST",url,true);
	http11.onreadystatechange = function handlewriteWinSizeToSession(){
		if(http11.readyState == 4){
		  if(http11.status == 200){	
			//alert(http11.responseText);			  
		 }	 
		}
	}; 
	http11.send(null);
}

	
/*
*	function is created by umesh sharma
*	populate the value into combobox for mobile versions
*/


var http12;
function populatever(value){	 

	http12 = makeInstance();
	var url = "populate_mo_vers.php?value="+value;		

	http12.open("GET",url,true);
	http12.onreadystatechange = handleSelectebox;
	http12.send(null);
}

/**
*	Function called to handle Check Selected Tags
*/
function handleSelectebox(){

	if(http12.readyState == 4){//alert('hello->0'+http12.responseText);
	  if(http12.status == 200){	//alert('hello');
		document.getElementById('versions').innerHTML=http12.responseText;			  
	  }	 
	}

	
}

//Function is created to set the session
var http13;
function setSession(){	 
	http13 = makeInstance();
	var url = "session_set.php";

	http13.open("POST",url,true);
	http13.onreadystatechange = function handlesetSession(){ if(http13.readyState == 4){
	  if(http13.status == 200){	
		//document.getElementById('versions').innerHTML=http13.responseText;			  
	  }	 
	}
 }
	http13.send(null);
}

/**
*	Function called to handle Check Selected Tags
*/

/*
*	code is used for showing the total view of a perticular tag on mouseover - by umesh kumar sharma
*	begins here
*/
var http14;
function tagviewdetails(value){	 
	if(value!=''){
		http14 = makeInstance();
		var url = "tag_view_count.php?value="+value;		
	
		http14.open("GET",url,true);
		http14.onreadystatechange = handleSelectebox;
		http14.send(null);
	}
}

/**
*	Function called to handle Check Selected Tags
*/
function handleSelectebox(){

	if(http14.readyState == 4){//alert('hello->0'+http14.responseText);
	  if(http14.status == 200){	//alert('hello');
		if(document.getElementById('viewcnt') != null){
			document.getElementById('viewcnt').innerHTML=http14.responseText;			  
		}
	  }	 
	}

	
}

/*
*	code is used to set the session
*	02 Oct 07
*	begins here
*/
var http15;
function savetagsinsession(insertarr,deletearr,page){
		//hide title code 
		http15 = makeInstance();
		var url = "remembertagstatistics.php?insertval="+insertarr+'&deleteval='+deletearr+'&page='+page;
		http15.open("GET",url,true);
		
		http15.onreadystatechange = savetagsinsessiondetails;
		http15.send(null);

}

/**
*	Function called to handle Check Selected Tags
*/
function savetagsinsessiondetails(){

	if(http15.readyState == 4){//alert('hello->0'+http14.responseText);
	  if(http15.status == 200){
		if(document.getElementById('countryshow') != null){
			//alert('hell'+http15.responseText);			  
		}
	  }	 
	}

	
}

//	Function to show the Graph
var http16;
function ShowGraph(yr,mon,date,str){
		//hide title code 
		http16 = makeInstance();
		var url = "creategraph.php?year="+yr+'&month='+mon+'&date='+date+'&string='+str;
		http16.open("GET",url,true);
		
		http16.onreadystatechange = ShowGraphdetails;
		http16.send(null);

}

/**
*	Function called to handle Check to show graph
*/
function ShowGraphdetails(){

	if(http16.readyState == 4){
	  if(http16.status == 200){
		if(document.getElementById('showgraph') != null){
			document.getElementById('showgraph').innerHTML = http16.responseText;			  
		}
	  }	 
	}

	
}

/*
*	ends here
*/

/*
*	Code is used to set the session value for Captcha Validation
*	@05/11/07
*	By Umesh Kumar Sharma
* 	Begins here...
*/
var http17;
function getSessionForCaptcha(){
		//hide title code 
		http17 = makeInstance();
		var url = "getsessionforcaptcha.php";
		http17.open("GET",url,true);
		
		http17.onreadystatechange = getSessionForCaptchadetails;
		http17.send(null);

}
function getSessionForCaptchadetails(){

	if(http17.readyState == 4){
	  if(http17.status == 200){
		if(document.getElementById('captsessval') != null){
			document.getElementById('captsessval').value = http17.responseText;			  
		}
	  }	 
	}

	
}
/*
*	...Ends Here
*/


/*
*	Code is used to get the country code based on the selected country from drop down box
*	@25/11/08
*	By Umesh Kumar Sharma
* 	Begins here...
*/
var http18;
function getCountryCodeList(value){
		//hide title code 
		http18 = makeInstance();
		var url = "getcountrycodelist.php?country="+value;
		http18.open("GET",url,true);
		
		http18.onreadystatechange = CountryCodeList;
		http18.send(null);

}
function CountryCodeList(){

	if(http18.readyState == 4){
	  if(http18.status == 200){
		if(document.getElementById('cc') != null){
			document.getElementById('cc').value = http18.responseText;			  
		}
	  }	 
	}

	
}
/*
*	...Ends Here
*/



/*	 
*	Function is used to set  the cookie values
*	Starts Here...
*/
function setCookie(name, value, expires, path, domain, secure) { document.cookie= name + "=" + escape(value) + ((expires) ? "; expires=" + expires.toGMTString() : "") + ((path) ? "; path=" + path : "") + ((domain) ? "; domain=" + domain : "") + ((secure) ? "; secure" : ""); 
}
/*
*	...Hnds Here
*/

/*	 
*	Function is used to get the cookie values 
*	Starts Here...
*/
function getCookie(name) {
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1) {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    } else {
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1) {
        end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
}

/**
*	Ends here
*/


