//---------------Global Varibale---------------
var div_name,row_name;
var div_name2;

var NAME,USERNAME,EMAIL,SADDRESS,ORGANIZATION,INTERESTED,PHONE,LAYOUT;
//--------------file uplder variable-----------------------
var uploader="";
var uploadDir="";
var dirname="";
var filename="";
var filepaths="";
var timeInterval="";
var idname="";

/////////// prototype ajax functions 
function reportError(request)
{
	alert('error report'+ request.responseText);
}
function reportException(request)
{
	alert('error exception'+ request.responseText);
}
function showdeadcenterdiv() {
// First, determine how much the visitor has scrolled

var scrolledX, scrolledY;
if( self.pageYoffset ) {
scrolledX = self.pageXoffset;
scrolledY = self.pageYoffset;
} else if( document.documentElement && document.documentElement.scrollTop ) {
scrolledX = document.documentElement.scrollLeft;
scrolledY = document.documentElement.scrollTop;
} else if( document.body ) {
scrolledX = document.body.scrollLeft;
scrolledY = document.body.scrollTop;
}

// Next, determine the coordinates of the center of browser's window

var centerX, centerY;
if( self.innerHeight ) {
centerX = self.innerWidth;
centerY = self.innerHeight;
} else if( document.documentElement && document.documentElement.clientHeight ) {
centerX = document.documentElement.clientWidth;
centerY = document.documentElement.clientHeight;
} else if( document.body ) {
centerX = document.body.clientWidth;
centerY = document.body.clientHeight;
}

// Xwidth is the width of the div, Yheight is the height of the
// div passed as arguments to the function:
var Xwidth=$('show_information').offsetWidth-300;
var Yheight=$('show_information').offsetHeight;
//alert(Xwidth);
//alert(Yheight);
//Xwidth=800;
//Xeight=800;
var leftoffset = scrolledX + (centerX - Xwidth) / 2;
var topoffset = (scrolledY + (centerY - Yheight) / 2)-300;
// The initial width and height of the div can be set in the
// style sheet with display:none; divid is passed as an argument to // the function
var o=document.getElementById('show_information');
var r=o.style;
r.position='absolute';
r.top = topoffset + 'px';
//r.left = leftoffset + 'px';
/*r.display = "block";*/
$('show_information').style.visibility=	"visible";
//Effect.Appear('show_information');
$('show_information').style.display='';
}


function getHeight() {
	var document_body = Screen.getBody();
	var innerHeight =(defined(self.innerHeight)&&!isNaN(self.innerHeight))?self.innerHeight:0;
	if (!document.compatMode || document.compatMode=="CSS1Compat") {
		var topMargin = parseInt(CSS.get(document_body,'marginTop'),10) || 0;
		var bottomMargin = parseInt(CSS.get(document_body,'marginBottom'), 10) || 0;
		return Math.max(document_body.offsetHeight + topMargin + bottomMargin,document.documentElement.clientHeight,document.documentElement.scrollHeight, Screen.zero(self.innerHeight));
		}
	return Math.max(document_body.scrollHeight, document_body.clientHeight,Screen.zero(self.innerHeight));
}
function showLoader(request)
{
  if($('iframe_bg'))
  {	
	 var iframe = $('iframe_bg');
    iframe.style.display = 'block';
	iframe.style.height = getHeight()+'px';
	//$('preload_bg').style.display='block';
	$('preloading').style.display='block';
  }
}
function destory_loader(request)
{
  if($('iframe_bg'))
  {
   $('iframe_bg').style.display='none';
   $('preloading').style.display='none';
  }
}
function send_ajax_request(url,params,success_method,error_method)
{
	var ajax = new Ajax.Request(url,
										{
											method: 'POST',
											parameters: params,
											onSuccess: success_method,
											onFailure: error_method,
											onException: reportException,
											onLoading: showLoader
											/*onLoaded: showLoader,
											onInteractive: showLoader*/
											
										}
									)
}

/////////// end /////////// prototype ajax functions 

///////// register page function/////////////




function checkk()
{
		var address = $('contact_form_saddress').value;
		var email = $('contact_form_email').value;
		base_url = '';
		
		
		
		NAME = $('contact_form_name').value;
		USERNAME = $('contact_form_username').value;
		EMAIL = $('contact_form_email').value;
		SADDRESS = $('contact_form_saddress').value;
		ORGANIZATION = $('contact_form_org').value;
		LAYOUT = $('layout').value;
		PHONE = $('contact_form_phone').value;
		
		
		if(NAME == '' || USERNAME == '' || EMAIL == '' || SADDRESS == '' || ORGANIZATION == '' || PHONE == '')
		{
				$('msgg').innerHTML = '<div style="font-size:14px;color:red;font-weight:bold;"> All Fields Are Neccessary! </div>';
				return false;
		}
		if(EMAIL != '')
		{
			var filter = /^([a-zA-Z0-9_.-])+@(([a-zA-Z0-9-])+.)+([a-zA-Z0-9]{2,4})+$/;
			var str = EMAIL;
			
			if(!filter.test(str))
			{
				$('msgg').innerHTML = '<div style="font-size:14px;color:red;font-weight:bold;"> Please Provide A Valid Email! </div>';
				return false;
			}
			
		}
		
		if(SADDRESS != '')
		{	
			if(SADDRESS.indexOf('.') > 0 || SADDRESS.indexOf(' ') > 0	)
			{
				$('msgg').innerHTML = '<div style="font-size:14px;color:red;font-weight:bold;"> Store Name Can Not Contain "." Or a Blank Space. </div>';
				return false;
			}
		}
		
	
		var url = "tahirjs/ch.php";
		var params = 'address='+address+'&email='+email;
		send_ajax_request(url,params,ch2,reportError);
		return false;
}
function ch2(request)
{
	str=request.responseText;

	if(str == 'email')
	{
		
		$('msgg').innerHTML = '<div style="font-size:14px;color:red;font-weight:bold;"> Email Already Exists . </div>';
		return false;
	}
	else if(str == 'address')
	{
		$('msgg').innerHTML = '<div style="font-size:14px;color:red;font-weight:bold;"> Shop Address Already Exists . </div>';
		return false;
	}
	else if(str == 'allocated')
	{
		$('msgg').innerHTML = '<div style="font-size:14px;color:red;font-weight:bold;"> Sorry! Shop Name Not Available . </div>';
		return false;
	}

	else
	{
		
		$('iframe_bg1').style.display = 'block';
		showdeadcenterdiv();//$('show_information').style.display = 'block';
		$('msggg').innerHTML = '<div style="font-size:14px;color:red;font-weight:bold;">Please Wait! <img src="tahirjs/loading.gif" /></div>';

		NAME = $('contact_form_name').value;
		var sec = $('sec').value;
		var EMAIL = $('contact_form_email').value;
		
		var url = 'tahirjs/sendemail.php';
		var params = 'sec='+sec+'&email='+EMAIL+'&name='+NAME;
		send_ajax_request(url,params,ch3,reportError);
		
		
	
	}

}
function ch3(request)
{
		str=request.responseText;
		if(str == 'yes')
		{
			$('msggg').innerHTML = '<div style="font-size:14px;color:#555;width:446px;line-height:20px;text-align:left;padding-left:65px;float:left;"><b style="line-height:18px;display:block;">An email message has been sent to you, check your inbox and enter the confirmation code in the box below</b> <br> * If you have not recieved any email, please <a style="cursor:pointer;" onclick="javascript: sendMail()"><strong>Click Here</strong></a></div>';
			$('secFiled').style.display = 'block';
		}
		
}

function createStore()
{
		var sec =  $('sec').value;
		var sec2 =  $('secCode').value;
		if(sec2 == '')
		{
			$('msggg').innerHTML = '<div style="color:#555555;float:left;font-size:14px;font-weight:bold;padding-bottom:10px;padding-left:60px;text-align:left;width:400px;">Please Fill In The Code ( If You Have Not Got Any Email Yet, Please <a style="cursor:pointer;" onclick="javascript: sendMail()"><strong>Click Here</strong></a></div>';
		}
		else if(sec == sec2)
		{
			
			var url = 'tahirjs/retcode.php';
			var params = 'email='+EMAIL;
			send_ajax_request(url,params,ch5,reportError);
			
			
		}
		else
		{
			$('msggg').innerHTML = '<div style="text-align:center;"><span style="font-size:15px;color:red;font-weight:bold;">Sorry Invalid Code!</span> <span style="font-size:13px;color:gray;font-weight:bold;"> <br> * If you have not recieved any email, please <a style="cursor:pointer;" onclick="javascript: sendMail()"><strong>Click Here</strong></a></span></div>';
		}
}


function sendMail()
{
	
	$('msggg').innerHTML = '<div style="font-size:14px;color:red;font-weight:bold;">Please Wait! <img src="tahirjs/loading.gif" /></div>';
	var sec =  $('sec').value;
	var url = 'tahirjs/sendemail.php';
	var params = 'sec='+sec+'&email='+EMAIL+'&name='+NAME;
	send_ajax_request(url,params,chttt,reportError);	

}
function ch4(){}
function chttt(){
	setTimeout('showmsggg()',1000);	
}
function showmsggg()
{
$('msggg').innerHTML = '<div style="font-size:14px;color:#555;width:446px;line-height:20px;text-align:left;padding-left:65px;float:left;"><b style="line-height:18px;display:block;">An email message has been sent to you, check your inbox and enter the confirmation code in the box below</b> <br> * If you have not recieved any email, please <a style="cursor:pointer;" onclick="javascript: sendMail()"><strong>Click Here</strong></a></div>';
}
function ch5(request)
{
			str=request.responseText;
			
			if(LAYOUT == 'img1')
				LAYOUT = 'BodyBuilding';
			else if(LAYOUT == 'img2')
				LAYOUT = 'CellPhones';
			else if(LAYOUT == 'img3')
				LAYOUT = 'VideoCamera';
			else if(LAYOUT == 'img4')
				LAYOUT = 'Luggage';
			else if(LAYOUT == 'img5')
				LAYOUT = 'default';
			else if(LAYOUT == 'img6')
				LAYOUT = 'Furnitures';
			else if(LAYOUT == 'img7')
				LAYOUT = 'Softwares';
			else if(LAYOUT == 'img8')
				LAYOUT = 'SunGlasses';
			else if(LAYOUT == 'img9')
				LAYOUT = 'Computers';
			else if(LAYOUT == 'img10')
				LAYOUT = 'Camera';
			
			$('msggg').innerHTML = '<div style="font-size:12px;color:green;font-weight:bold;">Please Wait! Your Store Is Being Created <img src="tahirjs/loading.gif" /></div>';
			var url = 'tahirjs/transport.php';
			var urll = 'http://www.bit-cart.com/stores';
			var params = 'action='+urll+'/index.php'+'&method=get&check=2&create=1&name='+NAME+'&username='+USERNAME+'&email='+EMAIL+'&org='+ORGANIZATION+'&phone='+PHONE+'&saddress='+SADDRESS+'&layout='+LAYOUT+'&rtc='+str;
			send_ajax_request(url,params,redi,reportError);		

}
function redi()
{
	
	$('msggg').innerHTML = '<span style="font-size:13px;color:gray;font-weight:bold;">Thank You For Your Patience, We Are Re-directing You To Your Store.<img src="tahirjs/loading.gif" /></span>';
	
	window.location = 'http://'+SADDRESS+'.bit-cart.com';	
}
