 //trim functions
function jtrim(value) {
        return LTrim(RTrim(value));
}
function trim(value) {
        return LTrim(RTrim(value));
}
// Removes leading whitespaces
function LTrim(value) {
        var re = /\s*((\S+\s*)*)/;
        return value.replace(re, "$1");
}
// Removes ending whitespaces
function RTrim(value) {
        var re = /((\s*\S+)*)\s*/;
        return value.replace(re, "$1");
}
function closeLayer(){
        New_overlay.hide();
}

/* Function for opening new window starts from here*/
function openWindow(page){
	if(page=='zipcode'){
		window.open("why_zipcode.php","whyzipcode","scrollbars=1,menubar=0,width=960,height=500");
	}
	else if(page=='zender'){
		window.open("why_zender.php","whyzender","scrollbars=1,menubar=0,width=960,height=500");
	}
	else if(page=='privacy_policy'){
		window.open("privacy_policy.php","privacypolicy","scrollbars=1,menubar=0,width=960,height=500");
	}
	else if(page=='terms_use'){
		window.open("terms_use.php","termsofuse","scrollbars=1,menubar=0,width=960,height=500");
	}
}
/* Function for opening new window ends here*/

/* Function for adding and removing new website textbox starts from here*/
function addRowToTable(){
  var lenweb =document.getElementById('no_web').value; 
  var tbl = document.getElementById('web_title_text');
  var lastRow = tbl.rows.length;
  // if there's no header row in the table, then iteration = lastRow + 1
  var iteration = 0;
  iteration=lenweb;	
  document.getElementById('no_web').value=parseFloat(iteration)+parseFloat(1);
  document.getElementById('url_iteration_count').value=iteration;
  
  var row = tbl.insertRow(lastRow);

  // left cell
  var cellLeft = row.insertCell(0);    
  cellLeft.height='40px';
  cellLeft.valign='middle';
  cellLeft.className='listing_web_title';	
  var textNode = document.createTextNode('Website title ' + iteration);
  cellLeft.appendChild(textNode);
  
  var tbl1 = document.getElementById('web_title_input');
  var lastRow1 = tbl1.rows.length;
  // if there's no header row in the table, then iteration = lastRow + 1
  var iteration1 = lastRow1 + 1;
  var row1 = tbl1.insertRow(lastRow1);

  // right cell
  var cellRight = row1.insertCell(0);
  var el = document.createElement('input');
  el.type = 'text';
  el.maxLength='25';
  el.name = 'website_title[]';
  el.id = 'website_title'+iteration1;
  cellRight.height='40px';
  cellRight.valign='top';
  el.className ='txtFeild1';

  cellRight.appendChild(el);
//=======================================

  var lastRow = tbl.rows.length;
  // if there's no header row in the table, then iteration = lastRow + 1
  //var iteration = lastRow + 1;
  var row = tbl.insertRow(lastRow);

  // left cell
  var cellLeft = row.insertCell(0);    
  cellLeft.height='40px';
  cellLeft.valign='middle';
  cellLeft.className='listing_web_title';
  var textNode = document.createTextNode('Website url ' + iteration);
  cellLeft.appendChild(textNode);
  
  var tbl1 = document.getElementById('web_title_input');
  var lastRow1 = tbl1.rows.length;
  // if there's no header row in the table, then iteration = lastRow + 1
  var iteration1 = lastRow1 + 1;
  var row1 = tbl1.insertRow(lastRow1);

  // right cell
  var cellRight = row1.insertCell(0);
  var el = document.createElement('input');
  el.type = 'text';
  el.name = 'website_url[]';
  //el.id = 'row'+iteration1;
  el.id='website_url'+iteration;
  cellRight.height='40px';
  cellRight.valign='top';
  el.className ='txtFeild1';

  cellRight.appendChild(el);

  var el=document.createElement('div');
  el.name="error_message";
  el.id='url_error'+iteration;
  el.className='error_msg';
  cellRight.appendChild(el);
    
 add_remove_link();
}

function add_remove_link() {
	if (document.getElementById('no_web').value<10) {
		document.getElementById('remove').innerHTML = '<a style="cursor:pointer;" class="subBOLD" onclick="addRowToTable()">Add another website</a>&nbsp;&nbsp;&nbsp;<a style="cursor:pointer;" class="subBOLD" onclick="removeRowFromTable()">Remove</a>';
	}else{	
		document.getElementById('remove').innerHTML = '<a style="cursor:pointer;" class="subBOLD" onclick="removeRowFromTable()">Remove</a>';
	}
}


function removeRowFromTable() {
	var tbl = document.getElementById('web_title_text');
	var lastRow = tbl.rows.length;
	tbl.deleteRow(lastRow - 1);
	tbl.deleteRow(lastRow - 2)

	var tbl1 = document.getElementById('web_title_input');
	var lastRow1 = tbl1.rows.length;
	tbl1.deleteRow(lastRow1 - 1);
	tbl1.deleteRow(lastRow1 - 2);
	document.getElementById('no_web').value=parseFloat(document.getElementById('no_web').value)-parseFloat(1);

	if (tbl1.rows.length == '0') {
		document.getElementById('remove').innerHTML = '<a style="cursor:pointer;" class="subBOLD" onclick="addRowToTable()">Add another website</a>';
	}else{
		add_remove_link();
	}	
	document.getElementById('url_iteration_count').value = document
			.getElementById('url_iteration_count').value - 1;
	
}	

/* Function for adding and removing new website textbox ends here*/

/* Function for adding and removing coupon textbox starts from here*/
function addRowToCouponTable(){
  var tbl = document.getElementById('coupon_text');
  var lencop =document.getElementById('no_cop').value;
 // alert(lencop);
  var lastRow = tbl.rows.length;
  // if there's no header row in the table, then iteration = lastRow + 1
  var iteration = lastRow + 1;
  if(iteration>1){
  	iteration = Math.ceil(iteration/3);
  }
  var num=parseFloat(lencop)+parseFloat(1);
  document.getElementById('no_cop').value=num;
  document.getElementById('iteration_count').value=iteration;
  var row = tbl.insertRow(lastRow);
  //var num=iteration + parseFloat(1);
  // left cell
  var cellLeft = row.insertCell(0);    
  cellLeft.height='40px';
  cellLeft.valign='middle';
  var textNode = document.createTextNode('Coupon title' + num + '*');
  cellLeft.appendChild(textNode);
  
  var tbl1 = document.getElementById('coupon_input');
  var lastRow1 = tbl1.rows.length;
  // if there's no header row in the table, then iteration = lastRow + 1
  var iteration1 = lastRow1 + 1;
  var row1 = tbl1.insertRow(lastRow1);

  // right cell
  var cellRight = row1.insertCell(0);
  cellRight.height='40px';
  var el = document.createElement('input');
  el.type = 'text';
  el.maxLength='25';	
  el.name = 'coupon_title[]';
  el.id = 'coupon_title'+iteration;
  el.style.margin="0 0 0 0";  
  el.height='40px';
  el.className ='txtFeild1';

  cellRight.appendChild(el);
  
  var el=document.createElement('div');
  el.name="error_coupon_title";
  el.id='coupon_title_error'+iteration;
  el.className='error_msg';	
   el.style.paddingBottom='10px';  
  cellRight.appendChild(el);
  //======================================================================
   var tbl = document.getElementById('coupon_text');
  var lastRow = tbl.rows.length;
  // if there's no header row in the table, then iteration = lastRow + 1
  //var iteration = lastRow + 1;
  var row = tbl.insertRow(lastRow);

  // left cell
  var cellLeft = row.insertCell(0);    
  cellLeft.height='125px';
  cellLeft.valign='top';
  var textNode = document.createTextNode('Coupon' + num +' description');
  cellLeft.appendChild(textNode);
  
  var tbl1 = document.getElementById('coupon_input');
  var lastRow1 = tbl1.rows.length;
  // if there's no header row in the table, then iteration = lastRow + 1
  var iteration1 = lastRow1 + 1;
  var row1 = tbl1.insertRow(lastRow1);

  // right cell
  var cellRight = row1.insertCell(0);
  cellRight.height='125px';
  var el = document.createElement('textarea');  
  el.name = 'coupon[]';
  //el.id = 'row'+iteration1;
  el.id = 'row'+iteration1;
  el.style.margin="0 0 0 0";    
  el.className ='txtArea1';

  cellRight.appendChild(el);
  //======================================================================
  //======================================================================
   var tbl = document.getElementById('coupon_text');
  var lastRow = tbl.rows.length;
  // if there's no header row in the table, then iteration = lastRow + 1
  //var iteration = lastRow + 1;
  var row = tbl.insertRow(lastRow);

  // left cell
  var cellLeft = row.insertCell(0);    
  cellLeft.height='40px';
  cellLeft.valign='middle';  
  var textNode = document.createTextNode('Expire date' + num + '*' );
  cellLeft.appendChild(textNode);
  
  var tbl1 = document.getElementById('coupon_input');
  var lastRow1 = tbl1.rows.length;
  // if there's no header row in the table, then iteration = lastRow + 1
  //var iteration1 = lastRow1 + 1;
  var row1 = tbl1.insertRow(lastRow1);

  // right cell
  var cellRight = row1.insertCell(0);
  var el = document.createElement('select');  
  var month_arr=new Array('Month','Jan','Feb','Mar','Apr','May','Jun','July','Aug','Sep','Oct','Nov','Dec');
  for(var j=0;j<month_arr.length;j++){
  	  var op = document.createElement('option');
	  var textNode = document.createTextNode(month_arr[j]);
	  op.value = j;
	  op.appendChild(textNode);
	  el.appendChild(op);
  }
  el.name = 'month[]';
  //el.id = 'row'+iteration1;
  el.id='month'+iteration;
  el.style.margin="0 0 0 0";    
  el.style.width="60px";
  el.className ='txtFeild1';  
  cellRight.appendChild(el);
  
  var el = document.createElement('select');
  var op = document.createElement('option');
  var textNode = document.createTextNode('Date');
  op.value = 0;
  op.appendChild(textNode);
  el.appendChild(op); 
  for(var i=1;i<32;i++){
	  var op = document.createElement('option');
	  var textNode = document.createTextNode(i);
	  op.value = i;
	  op.appendChild(textNode);
	  el.appendChild(op);
  } 
  el.name = 'date[]';
  //el.id = 'row'+iteration1;
  el.id='date'+iteration;
  el.style.margin="0 0 0 0";    
  el.style.width="60px";
  el.className ='txtFeild1';
  cellRight.appendChild(el);
  
  var el = document.createElement('select'); 
  var date = new Date();
  var current_year = date.getFullYear();
  var add_year = 20;
  var op = document.createElement('option');
  var textNode = document.createTextNode('Year');
  op.value = 0;
  op.appendChild(textNode);
  el.appendChild(op);
  for(var i=0;i<add_year;i++){
	  var op = document.createElement('option');
	  var textNode = document.createTextNode(parseInt(current_year) + parseInt(i));
	  op.value = parseInt(current_year) + parseInt(i);
	  op.appendChild(textNode);
	  el.appendChild(op);
  } 
  el.name = 'year[]';
  //el.id = 'row'+iteration1;
  el.id='year'+iteration;	
  el.style.margin="0 0 0 0";    
  el.style.width="60px";
  el.className ='txtFeild1';
  cellRight.appendChild(el);

  var el=document.createElement('div');
  el.name="error_message";
  el.id='date_error_'+iteration;
  el.className='error_msg';
  el.style.paddingBottom='10px';	
  cellRight.appendChild(el);
  //======================================================================
  
  add_remove_coupon_link();
}

function add_remove_coupon_link(){
//alert(document.getElementById('no_cop').value);
	if(document.getElementById('no_cop').value<10){
        	document.getElementById('coupon_remove').innerHTML='<a style="cursor:pointer;" class="subBOLD" onclick="addRowToCouponTable()">Add another coupon</a>&nbsp;&nbsp;&nbsp;<a style="cursor:pointer;" class="subBOLD" onclick="removeRowFromCouponTable()">Remove</a>';
        }else{
        	document.getElementById('coupon_remove').innerHTML='<a style="cursor:pointer;" class="subBOLD" onclick="removeRowFromCouponTable()">Remove</a>';
        }
}

function removeRowFromCouponTable()
{
	
  document.getElementById('no_cop').value=document.getElementById('no_cop').value-parseFloat(1);
  var tbl = document.getElementById('coupon_text');
  var lastRow = tbl.rows.length;
  tbl.deleteRow(lastRow - 1);
  tbl.deleteRow(lastRow - 2);
  tbl.deleteRow(lastRow - 3);
  
  var tbl1 = document.getElementById('coupon_input');
  var lastRow1 = tbl1.rows.length;
  tbl1.deleteRow(lastRow1 - 1);
  tbl1.deleteRow(lastRow1 - 2);
  tbl1.deleteRow(lastRow1 - 3);
  
  if (tbl1.rows.length == '0') {
		document.getElementById('remove').innerHTML = '<a style="cursor:pointer;" class="subBOLD" onclick="addRowToCouponTable()">Add another website</a>';
	}else{
		add_remove_coupon_link;
	}	
	document.getElementById('iteration_count').value = document.getElementById('iteration_count').value - 1;
	
	
	
  /*
  if(tbl1.rows.length=='0'){
  	document.getElementById('coupon_remove').innerHTML='<a style="cursor:pointer;" class="subBOLD" onclick="addRowToCouponTable()">Add coupon</a>';
  }
  document.getElementById('iteration_count').value=document.getElementById('iteration_count').value-1;
  */
}
/* Function for adding and removing coupon textbox ends here*/

/* Function for adding and removing photo textbox starts from here*/
function addRowToPhotoTable(){
  var lenphoto =document.getElementById('no_photo').value;
  var tbl = document.getElementById('photo_text');
  var lastRow = tbl.rows.length;
  // if there's no header row in the table, then iteration = lastRow + 1
  var iteration = 0;
  iteration=lenphoto;
  document.getElementById('no_photo').value=parseFloat(iteration)+parseFloat(1);
  document.getElementById('url_iteration_count').value=iteration;
  var row = tbl.insertRow(lastRow);

  // left cell
  var cellLeft = row.insertCell(0);    
  cellLeft.height='40px';
  cellLeft.valign='middle';
  cellLeft.className='listing_web_title';
  var textNode = document.createTextNode('Photo ' + iteration);
  cellLeft.appendChild(textNode);
  
  var tbl1 = document.getElementById('photo_input');
  var lastRow1 = tbl1.rows.length;
  // if there's no header row in the table, then iteration = lastRow + 1
  var iteration1 = lastRow1 + 1;
  var row1 = tbl1.insertRow(lastRow1);

  // right cell
  var cellRight = row1.insertCell(0);
  var el = document.createElement('input');
  el.type = 'file';
  el.name = 'photo[]';
  el.id = 'row'+iteration1;
  el.style.margin="0 0 20px 0";  
  el.height='40px';
  el.className ='txtFeild1';

  cellRight.appendChild(el);
  //==================================================================
  var tbl = document.getElementById('photo_text');
  var lastRow = tbl.rows.length;
  // if there's no header row in the table, then iteration = lastRow + 1
  //var iteration = lastRow + 1;
  var row = tbl.insertRow(lastRow);

  // left cell
  var cellLeft = row.insertCell(0);    
  cellLeft.height='120px';
  cellLeft.valign='middle';
  cellLeft.className='listing_web_title';
  var textNode = document.createTextNode('Photo Description ' + iteration);
  cellLeft.appendChild(textNode);
  
  var tbl1 = document.getElementById('photo_input');
  var lastRow1 = tbl1.rows.length;
  // if there's no header row in the table, then iteration = lastRow + 1
  var iteration1 = lastRow1 + 1;
  var row1 = tbl1.insertRow(lastRow1);

  // right cell
  var cellRight = row1.insertCell(0);
  var el = document.createElement('textarea');
  //el.type = 'textarea';
  el.name = 'description[]';
  el.id = 'row'+iteration1;
  el.style.margin="0 0 20px 0";  
  el.height='40px';
  el.className ='txtArea1';

  cellRight.appendChild(el);
  //==================================================================
  add_remove_photo_link();
}

function add_remove_photo_link(){
	if(document.getElementById('no_photo').value<10){
        	document.getElementById('photo_remove').innerHTML='<a style="cursor:pointer;" class="subBOLD" onclick="addRowToPhotoTable()">Add another photo</a>&nbsp;&nbsp;&nbsp;<a style="cursor:pointer;" class="subBOLD" onclick="removeRowFromPhotoTable()">Remove</a>';
	}else{
        	document.getElementById('photo_remove').innerHTML='<a style="cursor:pointer;" class="subBOLD" onclick="removeRowFromPhotoTable()">Remove</a>';
	}
		document.getElementById('url_iteration_count').value = document.getElementById('url_iteration_count').value - 1;	
}

function removeRowFromPhotoTable()
{
  var tbl = document.getElementById('photo_text');
  var lastRow = tbl.rows.length;
  tbl.deleteRow(lastRow - 1);
   tbl.deleteRow(lastRow - 2);
  
  var tbl1 = document.getElementById('photo_input');
  var lastRow1 = tbl1.rows.length;
  tbl1.deleteRow(lastRow1 - 1);
  tbl1.deleteRow(lastRow1 - 2);
  document.getElementById('no_photo').value=parseFloat(document.getElementById('no_photo').value)-parseFloat(1);	
  	if(tbl1.rows.length=='0'){
  		document.getElementById('photo_remove').innerHTML='<a style="cursor:pointer;" class="subBOLD" onclick="addRowToPhotoTable()">Add another photo</a>';
	}else{
		add_remove_photo_link();
  	}
		
}
/* Function for adding and removing photo textbox ends here*/

/* Function for change listing cost with time starts from here*/
function changeCost(time){
	if(time==6){
		document.getElementById('premium_cost_6month').style.display='';
		document.getElementById('premium_cost_12month').style.display='none';
		document.getElementById('sponsored_cost_6month').style.display='';
		document.getElementById('sponsored_cost_12month').style.display='none';
	}
	else if(time==12){
		document.getElementById('premium_cost_6month').style.display='none';
		document.getElementById('premium_cost_12month').style.display='';
		document.getElementById('sponsored_cost_6month').style.display='none';
		document.getElementById('sponsored_cost_12month').style.display='';
	}
}
/* Function for change listing cost with time ends here*/

/* Function for change category class starts from here*/
function changeClass(id){
	var catId="";
	for(var i=1;i<=5;i++){
		catId="cat"+i;
		if(id==i){
			document.getElementById(catId).className="current";
		}
		else{
			document.getElementById(catId).className="";
		}
	}
}
/* Function for change category class ends here*/

